<script>
    //google analytics
     var _gaq = _gaq || [];
     _gaq.push(['_setAccount', 'UA-12520737-6']);
     _gaq.push(['_trackPageview']);

     (function() {
       var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
       ga.src = 'https://ssl.google-analytics.com/ga.js';
       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
     })();

    chrome.browserAction.onClicked.addListener(function(tab){
        chrome.tabs.executeScript(null, {file:"script.js", allFrames:true});
        _gaq.push(['_trackEvent', 'browser_action', 'clicked']);
    });

    var scriptCode = {};
    var timer = null;
    chrome.extension.onRequest.addListener(function(request, sender, sendResponse){
        scriptCode[request.url] = {
            inlineScript : request.inlineScript,
            externalScript : request.externalScript
        };
        sendResponse({url:request.url});

        if(timer){
            clearTimeout(timer);
        }
        timer = setTimeout(function(){
            var url = chrome.extension.getURL('all_scripts.html');
            chrome.tabs.create({url:url});
        }, 300)
    });
</script>
